﻿using DeHeng_Mes.Model.Table;
using DeHeng_Mes.Utils;
using System.Collections.Generic;

namespace DeHeng_Mes.Dao
{
    public class AndonDao
    {
        /// <summary>
        /// 查询所有安灯报警
        /// </summary>
        /// <returns></returns>
        public List<AndonVoice> GetAndon()
        {
            using (var db = SqlSugarConfig.Db)
            {
                return db.Queryable<AndonVoice>().ToList();
            }
        }

        /// <summary>
        /// 插入安灯数据
        /// </summary>
        /// <param name="andonVoice"></param>
        /// <returns></returns>
        public bool InsertAndonData(AndonVoice andonVoice)
        {
            using (var db = SqlSugarConfig.Db)
            {
                return db.Insertable(andonVoice).ExecuteCommand() > 0;
            }
        }

        /// <summary>
        /// 检查是否包含该数据
        /// </summary>
        /// <param name="andonId"></param>
        /// <returns></returns>
        public bool QueryById(string andonId)
        {
            using (var db = SqlSugarConfig.Db)
            {
                return db.Queryable<AndonVoice>()
                    .Where(x => x.AndonId == andonId)
                    .Any();
            }
        }

        /// <summary>
        /// 根据Id删除数据
        /// </summary>
        /// <param name="andonId"></param>
        /// <returns></returns>
        public bool DeleteById(string andonId)
        {
            using (var db = SqlSugarConfig.Db)
            {
                return db.Deleteable<AndonVoice>()
                    .Where(x => x.AndonId == andonId)
                    .ExecuteCommand() > 0;
            }
        }
    }
}
